Skip to content

Follow continue-as-new in result() instead of returning None (#356) - #357

Merged
rmcdaniel merged 2 commits into
mainfrom
general/result-follow-continue-as-new
Nov 20, 2026
Merged

rmcdaniel merged 2 commits into
mainfrom
general/result-follow-continue-as-new

Conversation

@rmcdaniel

Copy link
Copy Markdown
Member

Fixes #356.

Bug

get_result reads the history of handle.run_id or desc.run_id. For a handle bound to run 1, which continued as new to run 2, run 1's history ends with WorkflowContinuedAsNew. That is not one of the terminal events the scan looks for, so result() returned None. It returned None whether run 2 completed or failed. The new tests reproduce this on main: one returns None where {"final": True} was expected, and another expected WorkflowFailed and got no exception.

Fix

get_result now follows the continue-as-new chain to the run that actually ended, the same way PHP's workflowResult(followCurrentRun: true) and the Rust SDK do:

  • It reads each WorkflowContinuedAsNew event's continued_to_run_id, which native Server records.
  • If no successor is recorded, it falls back to the newest run that the status read named.
  • It returns that run's result, or raises its typed failure.
  • A cycle or an unfollowable chain raises WorkflowFailed instead of returning None.

The per-run history scan moves into _run_terminal_outcome; its behavior for completed, failed, terminated, cancelled and timed-out runs is unchanged.

Interaction with #354: the history-free fast path in #354 applies only when the status read names the handle's run. A handle on run 1 therefore takes this history path and follows the chain. The two changes compose.

Tests (tests/test_result_continue_as_new.py)

Case Expected
Handle on run 1, continued to run 2, run 2 completed Run 2's result
Handle on run 1, continued to run 2, run 2 failed WorkflowFailed with run 2's message
Unpinned handle Unchanged; only run 2 is read
Three-run chain Followed run by run
No recorded successor Falls back to the newest run
Cycle WorkflowFailed

Five of these fail on main.

Local results (Python 3.14):

  • pytest tests/ -m "not integration": 7813 passed, 3 skipped.
  • ruff: clean.
  • mypy: clean.

🤖 Generated with Claude Code

A handle bound to a run that continued as new read that run's history,
found no completed/failed/terminated/cancelled/timed-out event (it ends
with WorkflowContinuedAsNew) and returned None. Follow the chain through
each WorkflowContinuedAsNew event's continued_to_run_id (falling back to
the newest run the status read names) to the run that ended, as PHP and
Rust do, and return its result or raise its typed failure. A chain that
cannot be followed raises WorkflowFailed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@rmcdaniel rmcdaniel added bug Something isn't working agent:general labels Nov 20, 2026
@sonarqubecloud

Copy link
Copy Markdown

@rmcdaniel
rmcdaniel merged commit 317d2f5 into main Nov 20, 2026
25 checks passed
rmcdaniel added a commit that referenced this pull request Nov 20, 2026
rmcdaniel added a commit that referenced this pull request Nov 20, 2026
Keeps both: this branch's transient retries, committed-completion rule
and outage logs, and main's decoded response cap and continue-as-new
result. Only CHANGELOG.md conflicted; both entries are kept.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent:general bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

result() on a handle bound to a run that continued as new silently returns None

1 participant